package main;

import java.awt.AWTException;
import java.awt.SystemTray;

import common.log.WindLog;

public class StartIconTray {

	public static void main(String[] args) {
		WindLog.getLogger().logInfo("checking support for SystemTray...");
		try{
		if (SystemTray.isSupported()) {

			DataController mdc = null;
			try {
				WindLog.getLogger().logInfo("setting DataController...");
				mdc = new DataController();
			} catch (Exception e1) {
				WindLog.getLogger().logSevere(
						"Initialize DataController :" + e1.getMessage());
			}
			if (mdc != null) {
				SystemTray tray = SystemTray.getSystemTray();
				WindLog.getLogger().logInfo("setting trayIcon...");
				WindTrayIcon trayIcon = new WindTrayIcon(mdc);
				WindLog.getLogger().logInfo("setting Refresh Thread...");
				RefreshThread rth = new RefreshThread(mdc.getMainDataSet(), mdc
						.getRefreshtime());
				rth.setIconNot(trayIcon);

				try {
					WindLog.getLogger()
							.logInfo("starting refreshing thread...");
					rth.start();
					WindLog.getLogger().logInfo("adding trayicon...");
					tray.add(trayIcon);
				} catch (AWTException e) {
					WindLog.getLogger().logSevere(
							"TrayIcon could not be added. :" + e.getMessage());
				}

			}
		}
	}catch (Exception e) {
			WindLog.getLogger().logSevere(
					"general error... :" + e.getMessage());
		}

	}

}
